import re
from datetime import datetime
from typing import Optional

def convert_option_symbol(symbol: str) -> str:
    """
    标准化期权代码转换（示例实现）
    输入格式：IO2203-C-4000 或 IO2203P4000
    输出格式：10001215（AKShare内部代码）
    """
    try:
        # 分离合约要素
        symbol = symbol.upper().replace('-','')
        match = re.match(r"([A-Z]{2})(\d{2})(\d{2})([CP])(\d+)", symbol)
        if not match:
            raise ValueError("无法识别的期权代码格式")

        underlying, year, month_code, call_put, strike = match.groups()
        
        # 转换月份代码（示例：H3→03）
        month_map = {'F':'01','G':'02','H':'03','J':'04','K':'05','M':'06',
                    'N':'07','Q':'08','U':'09','V':'10','X':'11','Z':'12'}
        month = month_map.get(month_code, month_code.zfill(2))
        
        # 生成AKShare内部代码（示例逻辑）
        return f"{underlying}{year}{month}{call_put}{strike.zfill(5)}"
    except Exception as e:
        raise ValueError(f"期权代码转换失败: {symbol} -> {str(e)}")